package com.flbill.mapper;

import com.flbill.pojo.entity.Expense;
import com.flbill.pojo.entity.Income;
import com.flbill.pojo.vo.ExpenseReportVO;
import com.flbill.pojo.vo.TransactionsPageVO;
import com.github.pagehelper.Page;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface TransactionsMapper {
    @Insert("insert into expense (user_id, amount, expense_time, expense_class, remark, create_time, update_time) " +
            "values (#{userId}, #{amount}, #{expenseTime}, #{expenseClass}, #{remark}, #{createTime}, #{updateTime})")
    void insert(Expense expense);

    @Insert("insert into income (user_id, amount, income_time, income_class, remark, create_time, update_time) " +
            "values (#{userId}, #{amount}, #{incomeTime}, #{incomeClass}, #{remark}, #{createTime}, #{updateTime})")
    void insertIncome(com.flbill.pojo.entity.Income income);

    Page<TransactionsPageVO> ExpensePagelist(Integer userId, LocalDate  start, LocalDate end);

    Page<TransactionsPageVO> IncomePageLIst(Integer userId, LocalDate start, LocalDate end);

    @Delete("delete from expense where expense_id = #{id}")
    void deleteExpense(Integer id);

    @Delete("delete from income where income_id = #{id}")
    void deleteIncome(Integer id);

    void updateExpense(Integer id, Expense expense);

    void updateIncome(Integer id, Income income);

    @Select("select sum(amount) as actual_expense from expense where user_id = #{userId} and expense_time between #{start} and #{end}")
    Float ExpensePie(Integer  userId, LocalDate start, LocalDate end);

    Float IncomePie(@Param("userId") Integer userId, @Param("start") LocalDate start, @Param("end") LocalDate end);

    List<Map<String, Object>> ExpenseBar(@Param("userId") Integer userId, @Param("start") LocalDate start, @Param("end") LocalDate end);
    List<Map<String, Object>> IncomeBar(@Param("userId") Integer userId, @Param("start") LocalDate start, @Param("end") LocalDate end);

    List<Income> selectIncomeDetails(@Param("userId") Integer userId, @Param("start") LocalDate start, @Param("end") LocalDate end);
    List<Expense> selectExpenseDetails(@Param("userId") Integer userId, @Param("start") LocalDate start, @Param("end") LocalDate end);
}
